<template>
	<view></view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		loginToken
	} from '@/stores'

	const tokenStore = loginToken()
	const WHITE_LIST = [
		'/pages/login/login',
		'/pages/home/home',
		'/pages/my/my',
		'/pages/map/LocationPicker',
		'/pages/agreement/user',
		'/pages/agreement/personal'
	]
	const checkToken = (url) => {
		if (WHITE_LIST.some(path => url.includes(path))) {
			return true
		}

		if (!tokenStore.token) {
			uni.redirectTo({
				url: '/pages/login/login?redirect=' + encodeURIComponent(url)
			})
			return false
		}
		return true
	}
	uni.addInterceptor('navigateTo', {
		invoke: (args) => checkToken(args.url)
	})
	uni.addInterceptor('switchTab', {
		invoke: (args) => checkToken(args.url)
	})
</script>

<style>
	view,
	text,
	image,
	button {
		margin: 0;
		padding: 0;
		box-sizing: border-box;
	}

	a {
		color: #007AFF;
		text-decoration: none;
	}

	page {
		background-color: #f4f4f4 !important;
		height: 100% !important;
	}

	.uni-page-wrapper {
		background-color: inherit !important;
		min-height: 100vh !important;
	}
</style>